/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.corespring.restaurant.dao.hibernate;

import java.util.List;
import org.corespring.restaurant.dao.EventoDao;
import org.corespring.restaurant.model.Evento;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Aldo
 */
@Repository
public class EventoDaoHibernate extends HibernateDaoSupport implements EventoDao {

    @Autowired
    public EventoDaoHibernate(SessionFactory sessionFactory) {
        setSessionFactory(sessionFactory);
    }

    @Override
    public List<Evento> obtenerEventos() {
        List list = getHibernateTemplate().find(" from Evento ");
        return list;
    }

    @Override
    public Evento obtenerEventoById(int sId) {
        Evento evento = getHibernateTemplate().get(Evento.class, sId);
        return evento;
    }

    @Override
    public void grabarEvento(Evento objEvt) {
        getHibernateTemplate().saveOrUpdate(objEvt);
        getHibernateTemplate().flush();
    }

    @Override
    public void eliminarEvento(int sId) {
        Evento objevt = obtenerEventoById(sId);
        getHibernateTemplate().delete(objevt);
    }
}
